package com.lzl.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class StarAssistant implements InvocationHandler{

    Object target  = null;

    /**
     * 获取代理对象
     * @param object
     * @return
     */
    public Object getProxy(Object object){
        this.target = object;
        Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(),target.getClass().getInterfaces(),this);
        return proxy;
    }

    /**
     * 调用代理方法
     * @param proxy
     * @param method
     * @param args
     * @return
     * @throws Throwable
     */
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object object = method.invoke(this.target,args);
        after();
        return object;
    }

    private void before(){
        System.out.println("我是刘德化助理");
    }

    private void after(){
        System.out.println("合作愉快");
    }

    public void method(String a,int b,long c){}
}
